
define(['notice','document','order','inventory','share'],function(notice,doc,order,inventory,share){

    var id;

    var map = {
        notice : notice,
        document : doc,
        order : order,
        inventory : inventory,
        share : share
    };

    function init(labID) {
        id = labID;
        var lab = getModule();
        getEvent(lab);
        $('header').after(lab);
    }

    function remove() {
        $('#lab').remove();
    }

    function trigger(type,flag) {
        var module = $("[data-type="+ type +"]");
        module.siblings('.active').removeClass('active');
        module.addClass('active');
        removeContent();
        map[type].init('lab/'+ id + '/' + type,flag);
    }

    function getEvent(module) {
       var lis = module.find('#lab-nav li');
       lis.click(function() {
           trigger($(this).data('type'),true);
        });
    }

    function removeContent() {
        var content = $('#module-content');
        content.children().slideUp('slow');
        content.empty();
    }

    function getModule() {
        var lab;
        $.ajax({
            async : false,
                    method : 'GET',
                    url : 'app/lab/lab.html',
                    datType : 'string',
                    success : function(response){
                    if(typeof(response) === 'string'){
                        lab = response;
                    }
            }
        });
        return $(lab);
    }

    return {
        init : init,
        remove : remove,
        trigger : trigger
    }
});